package com.yunkuhui.www.demo.conf;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "mongodb")
public class MongodbConf {

	private String uri;

	private MongodbConf[] mongodbConf;

	@SuppressWarnings("all")
	public MongoTemplate getMongoTemplate() {
		MongoClientURI mongoClientURI = new MongoClientURI(uri);
		MongoClient mongoClient = new MongoClient(mongoClientURI);
		return new MongoTemplate(mongoClient, mongoClientURI.getDatabase());
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	public MongodbConf[] getMongodbConf() {
		return mongodbConf;
	}

	public void setMongodbConf(MongodbConf[] mongodbConf) {
		this.mongodbConf = mongodbConf;
	}
}
